home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / mhavoc.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  4KB  |  192 lines

  1. /***************************************************************************
  2.  
  3.   mhavoc.c (machine)
  4.  
  5.   Functions to emulate general aspects of the machine
  6.   (RAM, ROM, interrupts, I/O ports)
  7.  
  8. ***************************************************************************/
  9. #include "driver.h"
  10. #include "vidhrdw/avgdvg.h"
  11. #include "cpu/m6502/m6502.h"
  12.  
  13. static int gamma_data;
  14. static int alpha_data;
  15. static int alpha_rcvd;
  16. static int alpha_xmtd;
  17. static int gamma_rcvd;
  18. static int gamma_xmtd;
  19.  
  20. static int bank_select;
  21. static int player_1;
  22.  
  23. #define LS161_CLOCK 2*5000
  24.  
  25. static void *gamma_timer = NULL;
  26. static void mhavoc_gamma_irq(int param);
  27.  
  28. WRITE_HANDLER( mhavoc_ram_banksel_w )
  29. {
  30.     static int bank[2] = { 0x20200, 0x20800 };
  31.     unsigned char *RAM = memory_region(REGION_CPU1);
  32.  
  33.     data&=0x01;
  34.     logerror("Alpha RAM select: %02x\n",data);
  35.     cpu_setbank (1, &RAM[bank[data]]);
  36. }
  37.  
  38. WRITE_HANDLER( mhavoc_rom_banksel_w )
  39. {
  40.     static int bank[4] = { 0x10000, 0x12000, 0x14000, 0x16000 };
  41.     unsigned char *RAM = memory_region(REGION_CPU1);
  42.  
  43.  
  44.     data &= 0x03;
  45.  
  46.     logerror("Alpha ROM select: %02x\n",data);
  47.     cpu_setbank (2, &RAM[bank[data]]);
  48. }
  49.  
  50. void mhavoc_init_machine (void)
  51. {
  52.     /* Set all the banks to the right place */
  53.     mhavoc_ram_banksel_w (0,0);
  54.     mhavoc_rom_banksel_w (0,0);
  55.     bank_select = -1;
  56.     alpha_data=0;
  57.     gamma_data=0;
  58.     alpha_rcvd=0;
  59.     alpha_xmtd=0;
  60.     gamma_rcvd=0;
  61.     gamma_xmtd=0;
  62.     player_1 = 0;
  63.     if (gamma_timer)
  64.             timer_remove(gamma_timer);
  65.     gamma_timer = timer_pulse(TIME_IN_HZ(LS161_CLOCK/16), 0, mhavoc_gamma_irq);
  66. }
  67.  
  68. /* Read from the gamma processor */
  69. READ_HANDLER( mhavoc_gamma_r )
  70. {
  71.     logerror("  reading from gamma processor: %02x (%d %d)\n", gamma_data, alpha_rcvd, gamma_xmtd);
  72.     alpha_rcvd=1;
  73.     gamma_xmtd=0;
  74.     return gamma_data;
  75. }
  76.  
  77. /* Read from the alpha processor */
  78. READ_HANDLER( mhavoc_alpha_r )
  79. {
  80.     logerror("\t\t\t\t\treading from alpha processor: %02x (%d %d)\n", alpha_data, gamma_rcvd, alpha_xmtd);
  81.     gamma_rcvd=1;
  82.     alpha_xmtd=0;
  83.     return alpha_data;
  84. }
  85.  
  86. /* Write to the gamma processor */
  87. WRITE_HANDLER( mhavoc_gamma_w )
  88. {
  89.     logerror("  writing to gamma processor: %02x (%d %d)\n", data, gamma_rcvd, alpha_xmtd);
  90.     gamma_rcvd=0;
  91.     alpha_xmtd=1;
  92.     alpha_data = data;
  93.     cpu_cause_interrupt (1, M6502_INT_NMI);
  94.  
  95.     /* the sound CPU needs to reply in 250microseconds (according to Neil Bradley) */
  96.     timer_set (TIME_IN_USEC(250), 0, 0);
  97. }
  98.  
  99. /* Write to the alpha processor */
  100. WRITE_HANDLER( mhavoc_alpha_w )
  101. {
  102.     logerror("\t\t\t\t\twriting to alpha processor: %02x %d %d\n", data, alpha_rcvd, gamma_xmtd);
  103.     alpha_rcvd=0;
  104.     gamma_xmtd=1;
  105.     gamma_data = data;
  106. }
  107.  
  108. /* Simulates frequency and vector halt */
  109. READ_HANDLER( mhavoc_port_0_r )
  110. {
  111.     int res;
  112.  
  113.     res = readinputport(0);
  114.     if (player_1)
  115.         res = (res & 0x3f) | (readinputport (5) & 0xc0);
  116.  
  117.     /* Emulate the 2.4Khz source on bit 2 (divide 2.5Mhz by 1024) */
  118.     if (cpu_gettotalcycles() & 0x400)
  119.         res &=~0x02;
  120.     else
  121.         res|=0x02;
  122.  
  123.     if (avgdvg_done())
  124.         res |=0x01;
  125.     else
  126.         res &=~0x01;
  127.  
  128.     if (gamma_rcvd==1)
  129.         res |=0x08;
  130.     else
  131.         res &=~0x08;
  132.  
  133.     if (gamma_xmtd==1)
  134.         res |=0x04;
  135.     else
  136.         res &=~0x04;
  137.  
  138.     return (res & 0xff);
  139. }
  140.  
  141. READ_HANDLER( mhavoc_port_1_r )
  142. {
  143.     int res;
  144.  
  145.     res=readinputport(1);
  146.  
  147.     if (alpha_rcvd==1)
  148.         res |=0x02;
  149.     else
  150.         res &=~0x02;
  151.  
  152.     if (alpha_xmtd==1)
  153.         res |=0x01;
  154.     else
  155.         res &=~0x01;
  156.  
  157.     return (res & 0xff);
  158. }
  159.  
  160. WRITE_HANDLER( mhavoc_out_0_w )
  161. {
  162.     if (!(data & 0x08))
  163.     {
  164.         logerror("\t\t\t\t*** resetting gamma processor. ***\n");
  165.         cpu_set_reset_line(1,PULSE_LINE);
  166.         alpha_rcvd=0;
  167.         alpha_xmtd=0;
  168.         gamma_rcvd=0;
  169.         gamma_xmtd=0;
  170.     }
  171.     player_1 = data & 0x20;
  172.     /* Emulate the roller light (Blinks on fatal errors) */
  173.     osd_led_w (2, data & 0x01);
  174. }
  175.  
  176. WRITE_HANDLER( mhavoc_out_1_w )
  177. {
  178.     osd_led_w (1, data & 0x01);
  179.     osd_led_w (0, (data & 0x02)>>1);
  180. }
  181.  
  182. static void mhavoc_gamma_irq(int param)
  183. {
  184.     cpu_set_irq_line(1,0,HOLD_LINE);
  185. }
  186.  
  187. WRITE_HANDLER( mhavoc_irqack_w )
  188. {
  189.     timer_reset( gamma_timer, TIME_IN_HZ(LS161_CLOCK/16));
  190.     cpu_set_irq_line(1,0,CLEAR_LINE);
  191. }
  192.